<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 20px">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>属性模版列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column prop="id" label="ID" ></el-table-column>
      <el-table-column prop="name" label="姓名" ></el-table-column>
      <el-table-column prop="pinyin" label="拼音"></el-table-column>
      <el-table-column prop="keywords" label="关键字"></el-table-column>
      <el-table-column prop="sort" label="排列序号"></el-table-column>
      <el-table-column  label="按钮">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" size="mini" circle></el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini" @click="openDeleteConfirm(scope.row)" circle></el-button>
        </template>
      </el-table-column>

    </el-table>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: []
    }
  },
  methods:{
    handleDelete(attributetemplate){
      let url = 'http://localhost:9080/attribute-templates/'+attributetemplate.id+'/delete';
      this.axios.post(url).then((response)=>{
        let responseBody = response.data;
        if (responseBody.state!=10000){
          this.$message.error(responseBody.message);
        }
        this.loadAttributeTemplateList();
      })
    },
    openDeleteConfirm(attributetemplate){
      let message = '此操作将永久删除改属性模版, 是否继续?';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(attributetemplate)
      }).catch(() => {

      });
    },
    loadAttributeTemplateList(){
      let url ='http://localhost:9080/attribute-templates'
      this.axios.get(url).then((response)=>{
        let responseBody = response.data;
        this.tableData = responseBody.data;
      })
    }
  },
  mounted() {
    this.loadAttributeTemplateList();
  }
}
</script>
